<script lang="ts">
import {defineComponent} from 'vue'
import DialogAndBlock from "@/components/DialogAndBlock/index.vue";
import {downloadReq} from "@/api/download.ts";
import DynamicTable from "@/components/DynamicTable3/index.vue";
import {TableConfigItem} from "@/components/DynamicTable3/types.ts";
import {ElMessageBox} from "element-plus";

export default defineComponent({
  name: "ThreadManager",
  components: {DynamicTable, DialogAndBlock},
  data(){
    return {
      tableConfigList:[
        {
          label: '下载类型',
          prop: 'downloadType',
        },
        {
          label: '下载id',
          prop: 'downloadId',
        },
        {
          label: '线程id',
          prop: 'downloadSelfId',
        },
        {
          label: '保存路径',
          prop: 'savePath',
        },
        {
          label: '操作',
          slotName: 'caozuo',
          align: 'center',
          minWidth: '120px',
        },
      ] as TableConfigItem[],
      threadInfo: {
        activeCount: 0,
        downloadThreads: 0,
        downloadThreadInfoList: []
      }
    }
  },
  methods: {
    open() {
      this.$refs.Dialog.open()
      this.getInfo()
    },
    getInfo() {
      downloadReq.threadInfo().then(res=>{
        this.threadInfo = res.data
      })
    },
    deleTheard(row){
      ElMessageBox.confirm("是否删除","提示").then(()=>{
        downloadReq.deleTheard(row.downloadSelfId).then(res=>{
          this.getInfo()
        })
      })
    }
  }
})
</script>

<template>
  <DialogAndBlock
    title="线程管理"
    ref="Dialog"
    content-overflow="auto"
  >
    <div>
      <el-button
        @click="getInfo"
      >刷新</el-button>
    </div>
    <div>下载线程池当前激活线程数量：{{threadInfo.activeCount}}</div>
    <div>已经创建的线程数量：{{threadInfo.downloadThreads}}</div>
    <div>
      <DynamicTable
        :data="threadInfo.downloadThreadInfoList"
        :table-config-list="tableConfigList"
        :created-init-value="false"
      >
        <template #caozuo_default="{row, column, $index,tableData}">
          <el-button
            type="danger"
            text
            @click.stop="deleTheard(row)"
          >删除</el-button>
        </template>
      </DynamicTable>
    </div>
  </DialogAndBlock>
</template>

<style scoped lang="scss">
.mainInfo{
  display: flex;
}
</style>
